package lesson

import "fmt"

func Lesson05() {
	fmt.Println("package lesson file lesson/lesson05.go functino Lesson05")
	// Go的指针操作
	value := 1
	var point *int = &value

	fmt.Println("[value]:", value)
	fmt.Println("[&value]:", &value)
	fmt.Println("[point]:", point)
	fmt.Println("[*point]:", *point)

	//++ -- 只能放到单独一行
	value++
	fmt.Println("[value++]:", value)

	//条件表达式
	if 1 < 2 {
		fmt.Println("[1 < 2]:true")
	} else {
		fmt.Println("[1 < 2]:false")
	}

	if a := 2; a > 1 {
		fmt.Println("[a > 1]:true  [a]:", a)
	} else {
		fmt.Println("[a > 1]:false [a]:", a)
	}
	fmt.Println("[a]:", a) // undefined : a

	// 无限循环
	value = 1
	for {
		value++
		if value > 3 {
			break
		}
	}
	fmt.Println("[value]:", value)

	value = 1
	for value <= 3 {
		value++
		fmt.Println("[value]:", value)
	}

	for i := 0; i < 3; i++ {
		fmt.Println("[i]:", i)
	}

	// 注意：方法不要放到条件表达式中，每次循环会反复执行
	value_str := "string"
	for i := 0; i < len(value_str); i++ {
		fmt.Println("[i]:", i)
	}

	// 选择语句
	value = 2
	switch value {
	case 0:
		fmt.Println("a=0")
	case 1:
		fmt.Println("a=1")
	default:
		fmt.Println("default")
	}

	value = 1
	switch {
	case value >= 0:
		fmt.Println("a=0")
		fallthrough
	case value >= 1:
		fmt.Println("a=1")
	}

	switch i := 1; {
	case i >= 0:
		fmt.Println("i=0")
		fallthrough
	case i >= 1:
		fmt.Println("i=1")
	}

	// 跳转语句
LABEL1:
	for {
		for i := 0; i < 10; i++ {
			if i > 3 {
				break LABEL1 // 会跳出指定标签的循环
				// goto LABEL1 // 不会跳出循环回重新执行标签语句
			}
		}
	}
	fmt.Println("break jump 2 loop success")

LABEL2:
	for i := 0; i < 10; i++ {
		fmt.Println(i)
		for {
			fmt.Println("continue")
			continue LABEL2
		}

	}
	fmt.Println("continue jump 2 loop success")

	// homework
LABEL:
	for i := 0; i < 10; i++ {
		for {
			fmt.Println("[i]:", i)
			continue LABEL
		}
	}
}
